//
//  ThemeStatusBarStylePicker.swift
//  HeadlineNews
//
//  Created by han on 2019/7/26.
//  Copyright © 2019 han. All rights reserved.
//

import UIKit

#if os(tvOS)

final class ThemeStatusBarStylePicker: ThemePicker {}

#else

final class ThemeStatusBarStylePicker: ThemePicker {
    var animated = true
    
    convenience init(keyPath: String) {
        self.init(v: { ThemeStatusBarStylePicker.getStyle(stringStyle: ThemeManager.string(for: keyPath) ?? "") })
    }
    
    convenience init(keyPath: String, map: @escaping (Any?) -> UIStatusBarStyle) {
        self.init(v: { map(ThemeManager.value(for: keyPath))})
    }
    
    convenience init(styles: UIStatusBarStyle...) {
        self.init(v: { ThemeManager.element(for: styles) })
    }
}

extension ThemeStatusBarStylePicker {
    class func getStyle(stringStyle: String) -> UIStatusBarStyle{
        switch stringStyle.lowercased()  {
        case "default": return .default
        case "lightContent": return .lightContent
        default: return .default
        }
    }
}

extension ThemeStatusBarStylePicker: ExpressibleByArrayLiteral {
    convenience init(arrayLiteral elements: UIStatusBarStyle...) {
        self.init(v: { ThemeManager.element(for: elements) })
    }
}

extension ThemeStatusBarStylePicker: ExpressibleByStringLiteral {
    convenience init(stringLiteral value: String) {
        self.init(keyPath: value)
    }
    convenience init(extendedGraphemeClusterLiteral value: String) {
        self.init(keyPath: value)
    }
}

extension ThemeStatusBarStylePicker: ExpressibleByUnicodeScalarLiteral {
    convenience init(unicodeScalarLiteral value: String) {
        self.init(keyPath: value)
    }
}

extension ThemeStatusBarStylePicker {
    class func pickerWithKeyPath(_ keyPath: String) -> ThemeStatusBarStylePicker{
        return ThemeStatusBarStylePicker(keyPath: keyPath)
    }
    
    class func pickerWithKeyPath(_ keyPath: String, map: @escaping (Any?) -> UIStatusBarStyle) -> ThemeStatusBarStylePicker {
        return ThemeStatusBarStylePicker(v: { map(ThemeManager.value(for: keyPath)) })
    }
    
    class func pickerWithStyles(_ styles: [UIStatusBarStyle]) -> ThemeStatusBarStylePicker {
        return ThemeStatusBarStylePicker(v: { ThemeManager.element(for: styles) })
    }
    
    class func pickerWithStyles(_ styles: [String]) -> ThemeStatusBarStylePicker {
        return ThemeStatusBarStylePicker(v: { ThemeManager.element(for: styles.map(getStyle))})
    }
}

#endif
